<?php 
include 'header.php';
?>
<style type="text/css">
.survey{ display:block;width:100%;margin:10px auto;padding:0px 0px;border:1px solid #DEDEDE;background:#FFF;}
	.survey li{display:block;width:100%;margin:0px;padding:0px;clear:both; list-style:none}
	.survey li dl{display:block;width:100%;margin:0px;padding:0px;height:60px;}
	.survey li dl dt{display:block;width:100%;clear:both;text-indent:1.5em;line-height:30px;height:30px;font-weight:bold;font-size:14px;background-color:#DAFBFE; margin:0px}
	.survey li dl dd{display:block;float:left;margin:0px;width:40px;padding:0px 20px;line-height:30px;height:30px;}
	
	.notchecked{background-color:#FEE3D1}
	.checked{background-color:#E6FFE8}
</style>
<div class="pageBox">
<div class="survey">
<ul>
	<li>
    <dd style="line-height:30px;">&nbsp;&nbsp;参评单位：<font color="red"><?php echo $department['name']; ?></font>
    <!--<select name="department_id">
        <option value="0">请选择</option>
        <?php foreach($departmentList as $item):?>
        <option value="<?php echo $item['id'];?>" <?php if($department['id']==$item['id']):?>selected="selected"<?php endif;?>>
        <?php echo str_repeat('-', $item['level']-1), $item['name'];?>
        </option>
        <?php endforeach;?>
    </select>-->
    <input type="hidden" name="department_id" value="<?php echo $department['id']; ?>" />
    </dd>
    </li>
	<?php foreach ($survey as $key=>$subject):?>
	<li id="subject_<?php echo $key+1;?>">
		<dl>
			<dt><?php echo $key+1; ?>、<?php echo $subject['subject'];?></dt>
			<?php foreach ($subject['option'] as $option):?>
			<dd><label><input type="radio" name="s_<?php echo $key+1;?>" value="<?php echo $option['value'];?>"><?php echo $option['label'];?></label></dd>
			<?php endforeach;?>
		</dl>
	</li>
	<?php endforeach;?>
    <li>
    	<dd>
        	<button id="save">提交</button>
        </dd>
    </li>
</ul>
</div>
</div>
<?php 
include 'footer.php';
?>
<script type="text/javascript" src="/ria/default/jquery.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	var checkData = {
		s_1: 0,
		s_2: 0,
		s_3: 0,
		s_4: 0,
		s_5: 0,
		s_6: 0,
		s_7: 0,
		s_8: 0,
		department_id: 0
	}
	
	$(':radio').live('click', function(){
		var domName = $(this).attr('name');
		checkData[domName] = $(this).val();
		$(this).parents("dl").addClass('checked');
	});
	
	$('#save').live('click', function(){
		var flag = false;
		//if($('select').find('option:selected').length){
		//	checkData.department_id = $('select').find('option:selected').val();
		//}//console.log(checkData);
		checkData.department_id = $("input[name='department_id']").val();
		$.each(checkData, function(index, val){
			if(val==0){
				$("input[name='"+index+"']").parents("dl").addClass('notchecked');
				flag = true;
			}
		});
		if(flag){
			alert('请把全部题目填写完整。');
		}else{
			if(confirm('确定提交吗？')){
				$.post(
					'/api/survey/save',
					checkData,
					function(ret){
						if(ret.code==200){
							alert('感谢您参与本次问卷调查');
							window.location.href="/";
						}else{
							alert(ret.msg);
						}
					},'JSON'
				);
			}
		}
	});
});
-->
</script>